﻿<?php
	require_once('syscfn.php');
	
		//打印前缀
		function get_pre_nums($totolnums,$currentnum){
				$formatstr = "%0" . $totolnums ."d";
				return  sprintf($formatstr,$currentnum);
		}
	
	
		//变换不同行之间的颜色	
		function getcolor() 
		{ 
			static $colorvalue;//定义一个静态变量 
			if($colorvalue=="#F9F9F9") 
				$colorvalue="#F4F4F4"; 
			else 
				$colorvalue="#F9F9F9"; 
			return($colorvalue); 
		}
		//获取当前时间
		function get_time($Unix_time,$use_array = false){
			if (!$use_array) {
				return date('H:i:s',$Unix_time);
			}
			else {
				$current_time = explode(':',date('H:i:s',$Unix_time));
				$time['hour'] = $current_time[0];
				$time['minut'] = $current_time[1];
				$time['second'] = $current_time[2];
				return $time;
			}
		}
		//获取当前日期
		function get_date($Unix_time,$use_array = false){
			if (!$use_array) {
				return date('Y-m-d',$Unix_time);	
			}
			else {
				$current_date = explode('-',date('Y-m-d',$Unix_time));
				$date['year'] = $current_date[0];
				$date['month'] = $current_date[1];
				$date['day'] = $current_date[2];
				return $date;
			}
		}
		//获取日历所用时间
		function get_date_for_calendar($Unix_time,$use_sub=false){
			$date_of_first = '';
			if (!$use_sub) {
				$date_of_first = date('Y,n,',$Unix_time);
				$date_of_first .= '1';
			}
			else {
				$date_of_first = date('Y-n-j',$Unix_time);
			}
			return $date_of_first;
		}
		//获取日期及时间
		function get_date_time($Unix_time){
			return get_date($Unix_time) . ' ' . get_time($Unix_time);
		}
		//获取无格式日期用于做HASH文件夹
		function get_dirname_by_time($Unix_time){
			return date('Ymd',$Unix_time);
		}
		//获取毫秒级时间戳,用来计算页面执行时间
		function get_microtime(){
			$time = microtime();
			$time = explode(" ",$time);
			$time = $time[1] + $time[0];
			return  $time;
		}
		//计算页面执行时间
		function get_running_time($start_time,$end_time){
			$time = $end_time - $start_time;
			$time = explode('.' , $time);
			$time = $time[0] . '.' . substr($time[1] , 0 ,6);
			return $time;
		}
		// 返回上一页函数
		function sa_exit($error_msg) {
			echo '
				<tr>
					<td align="center" valign="middle">
						<font color="FF0000">' . '错误页面' . '</font>
					</td>
				</tr>
				<tr>
					<td align="center" valign="middle">
			';
			echo "<p><font color='FF0000'>$error_msg</font></p>";
			echo "<p><a href=\"javascript:history.go(-1);\"><font color='FF0000'>返回上一页</font></a></p>";
			echo '
					</td>
				</tr>
			';
		}
		/**
		 * Enter description here...
		 *
		 * @param unknown_type $site_physical_dir
		 * @param unknown_type $smarty
		 * @param unknown_type $notice_mes
		 * @param unknown_type $webdb
		 * @param unknown_type $banner_mes
		 */
		function show_normal_mes($site_physical_dir,$smarty,$notice_mes,$webdb,$banner_mes){
			$start_time = get_microtime();
			$dir_prefix = get_dir_prefix($site_physical_dir);
			$smarty->assign('title',$err_mes);
			$smarty->assign('web_link',$webdb['server']);
			$smarty->assign('qq_num','13542920');
			$smarty->assign('prefix_dir',$dir_prefix);
			$templates = get_current_template();
			$smarty->assign('templates',$templates);
			//页眉
			$smarty->display('header.tpl');
			echo '
				<tr>
					<td align="center" valign="middle">
						<font color="FF0000">' . $banner_mes . '</font>
					</td>
				</tr>
				<tr>
					<td align="center" valign="middle">
			';
			echo "<p><font color='FF0000'>$notice_mes</font></p>";
			echo "<p><a href=\"javascript:history.go(-1);\"><font color='FF0000'>返回上一页</font></a></p>";
			echo '
					</td>
				</tr>
			';
			//页脚
			$running_time = get_running_time($start_time,get_microtime());
			$smarty->assign('running_time',$running_time);
			$smarty->display('footer.tpl');
			exit(-1);
		}
		/**
		 * Enter description here...
		 *
		 * @param unknown_type $site_physical_dir
		 * @param unknown_type $smarty
		 * @param unknown_type $notice_mes
		 * @param unknown_type $webdb
		 * @param unknown_type $banner_mes
		 */
		function show_normal_mesR($notice_mes,$banner_mes,$action = ''){
			$start_time = get_microtime();
			//如果有动作,就是显示错误信息
			if ($action != '') {
				$is_error = 1;
			}
			else 
				$is_error = 0;
			//初始化模版变量
			global $sysinfo;
			$page = init_smart_template_obj('message.html',CACHE_DIR,CACHE_DIR,TEMPLATE_DIR);
			$page->assign('dojoinit','');
			$page->assign("system",$sysinfo);
			$page->assign('title',$banner_mes);
			$page->assign('error',$is_error);
			$page->assign('jsstr','');
			$page->assign('action',$action);
			$page->assign('banner_mes',$banner_mes);
			$page->assign('notice_mes',$notice_mes);
			$page->assign("system",$sysinfo);
			$running_time = get_running_time($start_time,get_microtime());
			$page->assign('running_time',$running_time);
			$page->output();
			exit(-1);
		}
	
		
		
		//显示错误页面
		function show_error_mes($site_physical_dir,$smarty,$err_mes,$web_settings){
			$dir_prefix = get_dir_prefix($site_physical_dir);
			//删除某文件,解决备份死锁系统
			if (file_exists($dir_prefix . 'elsesky/backup')) {
				unlink($dir_prefix . 'elsesky/backup');
			}
			$start_time = get_microtime();
			$smarty->assign('title',$err_mes);
			$smarty->assign('web_link',$web_settings['server']);
			$smarty->assign('qq_num','13542920');
			$smarty->assign('prefix_dir',$dir_prefix);
			$templates = get_current_template();
			$smarty->assign('templates',$templates);
			//页眉
			$smarty->display('header.tpl');
			sa_exit($err_mes);
			//页脚
			$running_time = get_running_time($start_time,get_microtime());
			$smarty->assign('running_time',$running_time);
			$smarty->display('footer.tpl');
			exit(-1);
		}
		//获取客户端IP
		function get_remote_ip(){
			return $_SERVER['REMOTE_ADDR'];
		}
		//获取当前物理路径
		function get_current_dir(){
			$path_info = pathinfo($_SERVER['SCRIPT_FILENAME']);
			return $path_info['dirname'];
		}
		//获取当前文件所在文件夹所对应的网站的相对深度
		function get_dir_prefix($site_physical_dir){
			$current_path = get_current_dir();
			$depth_current_file = count(explode('/',$current_path));
			$depth_of_site = count(explode('/',$site_physical_dir)) - 1;
			$relative_depth = $depth_current_file - $depth_of_site;
			$prefix_dir = '';
			for ($i = 0; $i < $relative_depth; $i++){
				$prefix_dir .= '../';
			}
			return $prefix_dir;
		}
		//错误处理函数
		function Errhandler($err_num ,$err_string ,$errfile_name ,$errline_number ,$err_context){
			$errmsg = "错误 : $err_string 在文件 : $errfile_name 中第 $errline_number 行发现错误<br>";
			$halt_script = true;
			$notify = false;
			$remote = false;
			$dispaly = true;
			$stdlog = true;
			$email = false;
			$type = '';
			$logfile = '';
			$email_addr = 'elsesky@gmail.com';
			$remote_dbg = 'localhost';
			switch ($err_num){
				case E_COMPILE_ERROR :
				case E_CORE_ERROR:
				case E_ERROR:
					$type = '严重错误';
				break;
				case E_NOTICE:
				case E_PARSE:
					$type = '解析错误';
				break;
				case E_NOTICE:
					$type = '提示信息';
				case E_USER_NOTICE:
				case E_CORE_WARNING:
				case E_WARNING:
					$type = '警告';
					$halt_script = false;
				break;
				case E_COMPILE_WARNING:
				case E_USER_WARNING:
				
				default:
					$type = "未知错误";
				break;
			}
			if ($notify) {
				$errmsg = $type . $errmsg;
				if ($email) {
					error_log($errmsg , 1, $email_addr);
				}
				if ($remote) {
					error_log($errmsg, 2, $remote_dbg);
				}
				if ($dispaly) {
					echo $errmsg;
				}
				if ($stdlog) {
					if ($logfile == "") {
						error_log($errmsg , 0);
					}					
				}
			}
			if ($halt_script) {
				exit(-1);
			}
		}
		//添加转义符
		function ADD_addslashes($string, $force = 0) {
			if(!get_magic_quotes_gpc() || $force) {
				if(is_array($string) && count($string)) {
					foreach($string as $key => $val) {
						$string[$key] = ADD_addslashes($val, $force);
					}
				} else {
					$string = addslashes($string);
				}
			}
			return $string;
		}
		//去掉转义符号
		function STRIP_stripslashes($string, $force = 0){
			if (get_magic_quotes_gpc() || $force) {
				if (is_array($string) && count($string)) {
					foreach ($string as $key => $val){
						$string[$key] = STRIP_stripslashes($val,$force);
					}
				}else {
					$string = stripslashes($string);
				}
			}
			return $string;
		}
		//从数据库中查找出第一行
		function get_one($db_setting,$sql){
			$dbhost    = $db_setting['host'];
			$dbuser    = $db_setting['user'];
			$dbpw      = $db_setting['pass'];
			$dbname    = $db_setting['dbname'];
			$prefix_tb = $db_setting['tb_pre'];
			@$db = new mysqli($dbhost,$dbuser,$dbpw,$dbname);
			if (mysqli_connect_errno()) {
				echo mysqli_errno($db);
				return false;
			}
			$rs = $db->query($sql);
			//echo mysqli_error($db);
			$num_results = $rs->num_rows;
			if ($num_results < 1) {
				echo mysqli_error($db);
				return false;
			}
			$row = $rs->fetch_assoc();
			$db->close();
			return $row;
		}
		//初始化数据库数组
		function init_db_settings(){
			global $dbhost,$dbuser,$dbpw,$dbname,$prefix_tb,$site_physical_dir;
			$db_setting = array(
					'host' => $dbhost,
					'user' => $dbuser,
					'pass' => $dbpw,
					'dbname' => $dbname,
					'tb_pre' => $prefix_tb,
					'dir' => $site_physical_dir
				);
			return $db_setting;
		}
		//初始化服务器设定数组
		function init_web_settings(){
			global $webdb;
			return $webdb;
		}
		/**
		 * init_user_infos
		 *
		 * @param string 		$user_name    用户名
		 * @param string		$user_pass	  用户密码	
		 * @param string		$user_email	  用户邮箱	
		 * @param string		$user_gander  用户性别
		 * @param string		$user_age	  用户生日
		 * @param string		$self_mes	  用户个人消息
		 * @param string		$uid		  用户UID	
		 * 
		 * 初始化用户信息
		 * 这里的信息都是
		 * 不经过处理直接
		 * 保存的
		 * 
		 * @return array
		 */
		function init_user_infos($user_name,$user_pass,$user_email,$user_gander,$user_age,$self_mes,$uid,$gid,$albumname = '',$albuminfo = ''){
			$user_infos = array(
				'user_name' => $user_name,
				'user_pass' => $user_pass,
				'user_email' => $user_email,
				'user_gander' => $user_gander,
				'user_age' => $user_age,
				'self_mes' => $self_mes,
				'uid' => $uid,
				'gid' => $gid,
				'albumname' => $albumname,
				'albuminfo' => $albuminfo
			);
			return $user_infos;
		}
		/**
		 * 初始化文章信息
		 *
		 * @param int $blog_id
		 * @param int $article
		 * @param string $article_title
		 * @param str $author
		 * @param string $article_info
		 * @param int $authorid
		 * @param int $sort_id
		 * @param int $hits
		 * @param int $replies
		 * @param int $replies_page
		 * @param int $lastpost
		 * @param string $lastposter
		 * @param int $lastposterid
		 * @param int $posttime
		 * @param int $hidden
		 * @param int $isparseurl
		 * @param string $ipaddress
		 * @return array
		 */
		function init_article_infos($blog_id,$article,$article_title,$author,$article_info,$authorid,$sort_id,$hits,$replies,$replies_page,$lastpost,$lastposter,$lastposterid,$posttime,$hidden,$isparseurl,$ipaddress){
			$article_infos = array(
				'blog_id' => $blog_id,
				'article'=> $article,
				'article_title' => $article_title,
				'article_info' => $article_info,
				'author'=> $author,
				'authorid' =>$authorid,
				'sort_id' => $sort_id,
				'hits' => $hits,
				'replies'=> $replies,
				'replies_page' => $replies_page,
				'lastpost' => $lastpost,
				'lastposter' => $lastposter,
				'lastposterid' => $lastposterid,
				'posttime' => $posttime,
				'hidden' => $hidden,
				'isparseurl' => $isparseurl,
				'ipaddress' => $ipaddress
			);
			return $article_infos;
		}
		//设置网页过期(注意,必须在所有HTML文档发送之前发送该板块)
		function set_no_cache(){
			header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
			header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
			header("Cache-Control: no-store, no-cache, must-revalidate");
			header("Cache-Control: post-check=0, pre-check=0" , false);
			header("Pragma: no-cache");
		}
		//UBB代码解析器
		function ubb_create($post,$allow=array('pic'=>1,'flash'=>1,'fontsize'=>1,'wdbimg'=>1,'wdbcodes'=>1)){
	//		$post = htmlspecialchars($post); 
	//		$text = ereg_replace("\r\n","<br/>",$text); 
	//		$text = ereg_replace("\r","<br/>",$text);
	//		$text = nl2br($text); 
	//		$text = preg_replace_callback("/\[code\](.+?)\[\/code\]/is",
	//		create_function(
	//              '$maches',
	//              "\$maches[1] = str_ireplace('<br />',\"\n\",\$maches[1]);
	//              \$maches[1] = str_ireplace('<br/>',\"\n\",\$maches[1]);
	//              \$text = '<blockquote> <font face=宋体 color=#333333>下面是代码:<br></font><textarea readonly style=\"background:background-color:#444444\" rows=12 cols=85  >' . \$maches[1] . '</textarea></blockquote>';
	//              return \$text;"
	//          ),$text);
	//		$text = preg_replace("/\\t/is"," ",$text); 
	//		$text = preg_replace("/\[h1\](.+?)\[\/h1\]/is","<h1>\\1</h1>",$text); 
	//		$text = preg_replace("/\[h2\](.+?)\[\/h2\]/is","<h2>\\1</h2>",$text); 
	//		$text = preg_replace("/\[h3\](.+?)\[\/h3\]/is","<h3>\\1</h3>",$text); 
	//		$text = preg_replace("/\[h4\](.+?)\[\/h4\]/is","<h4>\\1</h4>",$text); 
	//		$text = preg_replace("/\[h5\](.+?)\[\/h5\]/is","<h5>\\1</h5>",$text); 
	//		$text = preg_replace("/\[h6\](.+?)\[\/h6\]/is","<h6>\\1</h6>",$text); 
	//		$text = preg_replace("/\[url\](http:\/\/.+?)\[\/url\]/is","<a href=\"\\1\">\\1</a>",$text); 
	//		$text = preg_replace("/\[url\](.+?)\[\/url\]/is","<a href=\"http://\\1\">http://\\1</a>",$text); 
	//		$text = preg_replace("/\[url=(http:\/\/.+?)\](.*)\[\/url\]/is","<a href=\"\\1\">\\2</a>",$text); 
	//		$text = preg_replace("/\[url=(.+?)\](.*)\[\/url\]/is","<a href=\"http://\\1\">\\2</a>",$text); 
	//		$text = preg_replace("/\[img\](.+?)\[\/img\]/is","<img src=\"\\1\" alt=\"\" />",$text); 
	//		$text = preg_replace("/\[color=(.+?)\](.+?)\[\/color\]/is","<span style=\"color:\\1\">\\2</span>",$text); 
	//		$text = preg_replace("/\[size=(.+?)\](.+?)\[\/size\]/is","<span style=\"font-size:\\1\">\\2</span>",$text); 
	//		$text = preg_replace("/\[sup\](.+?)\[\/sup\]/is","<sup>\\1</sup>",$text); 
	//		$text = preg_replace("/\[sub\](.+?)\[\/sub\]/is","<sub>\\1</sub>",$text); 
	//		$text = preg_replace("/\[pre\](.+?)\[\/pre\]/is","<pre>\\1</pre>",$text); 
	//		$post = preg_replace("/\[email\](.+?)\[\/email\]/is","<a href=\"mailto:\\1\">\\1</a>",$post); 
	//		$text = preg_replace("/\[i\](.+?)\[\/i\]/is","<em>\\1</em>",$text); 
	//		$text = preg_replace("/\[b\](.+?)\[\/b\]/is","<strong>\\1</strong>",$text); 
	//		 
	//		return $text; 
	
			$post = nl2br($post);
			$post=preg_replace("/\[code\](.+?)\[\/code\]/eis","phpcode('\\1')",$post);
			$post=preg_replace("/\[html\](.+?)\[\/html\]/eis","htmlcode('\\1')",$post);
			if ($allow['wdbcodes'] == 1){
				$post =str_replace("<p>","<br><br>",$post);
				$post =str_replace("<br>"," <br>",$post);
				$post =str_replace("[u]","<u>",$post);
				$post =str_replace("[/u]","</u>",$post);
				$post =str_replace("[b]","<b>",$post);
				$post =str_replace("[/b]","</b>",$post);
				$post =str_replace("[i]","<i>",$post);
				$post =str_replace("[/i]","</i>",$post);
				$post =str_replace("[br]","<br>",$post);
				$post =str_replace("[list]","<ul>",$post);
				$post =str_replace("[/list]","</ul>",$post);
				$post =str_replace("[olist]","<ol>",$post);
				$post =str_replace("[/olist]","</ol>",$post);
				$post =str_replace("[*]","<li>",$post);
				$post =str_replace("[hr]","<hr width=40% align=left>",$post);
				$post =str_replace("[sup]","<sup>",$post);
				$post =str_replace("[/sup]","</sup>",$post);
				$post =str_replace('[url=&quot;','[url="',$post);
				$post =str_replace('&quot;]','"]',$post);
				$pattern = array(
					"/\[font=([^\[]*)\](.+?)\[\/font\]/is",
					"/\[color=([#0-9a-z]{1,10})\](.+?)\[\/color\]/is",
					"/\[email=([^\[]*)\](.+?)\[\/email\]/is",
					"/\[email\]([^\[]*)\[\/email\]/is",
					"/\[url=([^\[]*)\](.+?)\[\/url\]/is",
					"/\[url\]www\.([^\[]*)\[\/url\]/is",
					"/\[url\]([^\[]*)\[\/url\]/is",
					"/\[quote\]\s*(.*?)\s*\[\/quote\]/is",
					"/(\[fly\])(.+?)(\[\/fly\])/is",
					"/(\[move\])(.+?)(\[\/move\])/is",
					"/(\[align=)(left|center|right)(\])(.+?)(\[\/align\])/is",
					"/(\[shadow=)(\S+?)(\,)(.+?)(\,)(.+?)(\])(.+?)(\[\/shadow\])/is",
					"/(\[glow=)(\S+?)(\,)(.+?)(\,)(.+?)(\])(.+?)(\[\/glow\])/is",
				);
				$replacement = array(
					"<font face=\\1>\\2</font>",
					"<font color=\\1>\\2</font>",
					"<a href=\"mailto:\\1\">\\2</a>",
					"<a href=\"mailto:\\1\">\\1</a>",
					"<a href=\"\\1\" target=_blank>\\2</a>",
					"<a href=\"http://www.\\1\" target=_blank>\\1</a>",
					"<a href=\"\\1\" target=_blank>\\1</a>",
					"<table cellpadding=0 cellspacing=0 border=0 WIDTH=94% bgcolor=#F9F9F9 align=center class='noborder'><tr class=noborder><td class=noborder><table width=100% cellpadding=5 cellspacing=1 border=0><TR class=noborder><TD class=noborder>\\1</table></table>",
					"<marquee width=90% behavior=alternate scrollamount=3>\\2</marquee>",
					"<MARQUEE scrollamount=3>\\2</MARQUEE>",
					"<DIV Align=\\2>\\4</DIV>",
					"<table width=\\2 style=\"filter:shadow(color=\\4, direction=\\6 ,strength=2)\" class=\"noborder\">\\8</table>",
					"<table width=\\2 style=\"filter:glow(color=\\4, strength=\\6)\" class=\"noborder\">\\8</table>",
				);
				$post=preg_replace($pattern,$replacement,$post);
				if ($allow['iframe']) {
					$post = preg_replace("/\[iframe\]\s*(\S+?)\s*\[\/iframe\]/is","<IFRAME SRC=\\1 FRAMEBORDER=0 ALLOWTRANSPARENCY=true SCROLLING=YES WIDTH=97% HEIGHT=600></IFRAME>",$post);
				}
				if ($allow['pic']) {	    
					$post = preg_replace("/\[img\]\s*(\S+?)\s*\[\/img\]/is","<br><div><A class=\"article_pic\" rel=\"lightbox\" class=\"effectable\"  HREF=\\1 alt=新窗口打开图片><img src=\\1 border=0 onload=\"javascript:if(this.width>screen.width-350)this.width=screen.width-350\"></a></div>",$post);
					$post = preg_replace("/\[IMG ([^\[]*)\]/is","<img \\1>",$post);
				}
				if ($allow['flash']) {
					$post=eregi_replace("\\[swf\\](.+\.swf)\\[/swf\\]","<PARAM NAME=PLAY VALUE=TRUE><PARAM NAME=LOOP VALUE=TRUE><PARAM NAME=QUALITY VALUE=HIGH><embed src=\"\\1\" quality=high pluginspage=\"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\" type=\"application/x-shockwave-flash\"
					width=\"580\" height=\"400\"></embed><br><a href=\"\\1\" target=_blank>&nbsp 左键全屏观赏</a>",$post);
					$post = preg_replace("/(\[FLASH=)(\S+?)(\,)(\S+?)(\])(\S+?)(\[\/FLASH\])/is","<OBJECT classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0\" WIDTH=\\2 HEIGHT=\\4><PARAM NAME=MOVIE VALUE=\\6><PARAM NAME=PLAY VALUE=TRUE><PARAM NAME=LOOP VALUE=TRUE><PARAM NAME=QUALITY VALUE=HIGH><EMBED SRC=\\6 WIDTH=\\2 HEIGHT=\\4 PLAY=TRUE LOOP=TRUE QUALITY=HIGH></EMBED></OBJECT>",$post);
				}
				if ($allow['mpeg']) {
					$post = preg_replace("/\[wmv\]\s*(\S+?)\s*\[\/wmv\]/is","<EMBED src=\\1 HEIGHT=\"256\" WIDTH=\"314\" AutoStart=0 ></EMBED>",$post);
					$post = preg_replace("/\[mid\]\s*(\S+?)\s*\[\/mid\]/is","<EMBED src=\\1 HEIGHT=\"45\" WIDTH=\"314\" AutoStart=0 ></EMBED>",$post);
					$post = preg_replace("/\[asf\]\s*(\S+?)\s*\[\/asf\]/is","<object classid=\"clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95\" id=\"MediaPlayer1\" width=\"286\" height=\"225\" Standby=\"Loading Microsoft Windows Media Player components...\" 
						type=\"application/x-oleobject\">
						<PARAM NAME=\"FileName\" VALUE=\\1>
						<param name=\"AudioStream\" value=\"-1\">
						<param name=\"AutoSize\" value=\"-1\">
						<param name=\"AutoStart\" value=\"0\">
						<param name=\"AnimationAtStart\" value=\"-1\">
						<param name=\"AllowScan\" value=\"-1\">
						<param name=\"AllowChangeDisplaySize\" value=\"-1\">
						<param name=\"AutoRewind\" value=\"0\">
						<param name=\"Balance\" value=\"0\">
						<param name=\"BaseURL\" value>
						<param name=\"BufferingTime\" value=\"5\">
						<param name=\"CaptioningID\" value>
						<param name=\"ClickToPlay\" value=\"-1\">
						<param name=\"CursorType\" value=\"0\">
						<param name=\"CurrentPosition\" value=\"-1\">
						<param name=\"CurrentMarker\" value=\"0\">
						<param name=\"DefaultFrame\" value>
						<param name=\"DisplayBackColor\" value=\"0\">
						<param name=\"DisplayForeColor\" value=\"16777215\">
						<param name=\"DisplayMode\" value=\"0\">
						<param name=\"DisplaySize\" value=\"0\">
						<param name=\"Enabled\" value=\"-1\">
						<param name=\"EnableContextMenu\" value=\"-1\">
						<param name=\"EnablePositionControls\" value=\"-1\">
						<param name=\"EnableFullScreenControls\" value=\"0\">
						<param name=\"EnableTracker\" value=\"-1\">
						<param name=\"Filename\" value>
						<param name=\"InvokeURLs\" value=\"-1\">
						<param name=\"Language\" value=\"-1\">
						<param name=\"Mute\" value=\"0\">
						<param name=\"PlayCount\" value=\"1\">
						<param name=\"PreviewMode\" value=\"0\">
						<param name=\"Rate\" value=\"1\">
						<param name=\"SAMILang\" value>
						<param name=\"SAMIStyle\" value>
						<param name=\"SAMIFileName\" value>
						<param name=\"SelectionStart\" value=\"-1\">
						<param name=\"SelectionEnd\" value=\"-1\">
						<param name=\"SendOpenStateChangeEvents\" value=\"-1\">
						<param name=\"SendWarningEvents\" value=\"-1\">
						<param name=\"SendErrorEvents\" value=\"-1\">
						<param name=\"SendKeyboardEvents\" value=\"0\">
						<param name=\"SendMouseClickEvents\" value=\"0\">
						<param name=\"SendMouseMoveEvents\" value=\"0\">
						<param name=\"SendPlayStateChangeEvents\" value=\"-1\">
						<param name=\"ShowCaptioning\" value=\"0\">
						<param name=\"ShowControls\" value=\"-1\">
						<param name=\"ShowAudioControls\" value=\"-1\">
						<param name=\"ShowDisplay\" value=\"0\">
						<param name=\"ShowGotoBar\" value=\"0\">
						<param name=\"ShowPositionControls\" value=\"-1\">
						<param name=\"ShowStatusBar\" value=\"1\">
						<param name=\"ShowTracker\" value=\"-1\">
						<param name=\"TransparentAtStart\" value=\"0\">
						<param name=\"VideoBorderWidth\" value=\"0\">
						<param name=\"VideoBorderColor\" value=\"0\">
						<param name=\"VideoBorder3D\" value=\"0\">
						<param name=\"Volume\" value=\"-600\">
						<param name=\"WindowlessVideo\" value=\"0\">
						</object>",$post
					);
					$post = preg_replace("/\[ra\]\s*(\S+?)\s*\[\/ra\]/is","<object classid=\"clsid:CFCDAA03-8BE4-11CF-B84B-0020AFBBCCFA\" id=\"RAOCX\" width=\"253\" height=\"60\">
						<param name=\"_ExtentX\" value=\"6694\">
						<param name=\"_ExtentY\" value=\"1588\">
						<param name=\"AUTOSTART\" value=\"0\">
						<param name=\"SHUFFLE\" value=\"0\">
						<param name=\"PREFETCH\" value=\"0\">
						<param name=\"NOLABELS\" value=\"0\">
						<param name=\"SRC\" value=\"\\1\">
						<param name=\"CONTROLS\" value=\"StatusBar,ControlPanel\">
						<param name=\"LOOP\" value=\"0\">
						<param name=\"NUMLOOP\" value=\"0\">
						<param name=\"CENTER\" value=\"0\">
						<param name=\"MAINTAINASPECT\" value=\"0\">
						<param name=\"BACKGROUNDCOLOR\" value=\"#000000\">
						<embed src=\"\\1\" width=\"253\" autostart=\"true\" height=\"60\">
						</embed></object>",$post
					);
					$post = preg_replace("/\[rm\]\s*(\S+?)\s*\[\/rm\]/is","<object classid=clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA height=241 id=Player width=316 VIEWASTEXT>
						<param name=\"_ExtentX\" value=\"12726\">
						<param name=\"_ExtentY\" value=\"8520\">
						<param name=\"AUTOSTART\" value=\"0\">
						<param name=\"SHUFFLE\" value=\"0\">
						<param name=\"PREFETCH\" value=\"0\">
						<param name=\"NOLABELS\" value=\"0\">
						<param name=\"CONTROLS\" value=\"ImageWindow\">
						<param name=\"CONSOLE\" value=\"_master\">
						<param name=\"LOOP\" value=\"0\">
						<param name=\"NUMLOOP\" value=\"0\">
						<param name=\"CENTER\" value=\"0\">
						<param name=\"MAINTAINASPECT\" value=\"\\1\">
						<param name=\"BACKGROUNDCOLOR\" value=\"#000000\">
						</object><br>
						<object classid=clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA height=32 id=Player width=316 VIEWASTEXT>
						<param name=\"_ExtentX\" value=\"18256\">
						<param name=\"_ExtentY\" value=\"794\">
						<param name=\"AUTOSTART\" value=\"-1\">
						<param name=\"SHUFFLE\" value=\"0\">
						<param name=\"PREFETCH\" value=\"0\">
						<param name=\"NOLABELS\" value=\"0\">
						<param name=\"CONTROLS\" value=\"controlpanel\">
						<param name=\"CONSOLE\" value=\"_master\">
						<param name=\"LOOP\" value=\"0\">
						<param name=\"NUMLOOP\" value=\"0\">
						<param name=\"CENTER\" value=\"0\">
						<param name=\"MAINTAINASPECT\" value=\"0\">
						<param name=\"BACKGROUNDCOLOR\" value=\"#000000\">
						<param name=\"SRC\" value=\"\\1\">
						</object>",$post
					);
				}
				if ($allow['fontsize']) {
					$post = eregi_replace("\\[size=([^\\[]*)\\]","<font size=\\1>",$post);
					$post = str_replace("[/size]","</font>",$post);
					$post = str_replace("[/font]","</font>",$post);
					$post = str_replace("[/FONT]","</font>",$post);
				}
				if ($allow['iframe']) {
					$post = preg_replace("/\[iframe\]\s*(\S+?)\s*\[\/iframe\]/is","<IFRAME SRC=\\1 FRAMEBORDER=0 ALLOWTRANSPARENCY=true SCROLLING=YES WIDTH=97% HEIGHT=340></IFRAME>",$post);
				}
			}
			return $post;
		}
		//UBB表情标签解析器
		function site_face_tage($post,$template,$site_dir,$dir_prefix,$allow_faces = true){
			if ($allow_faces) {
				$dir_prefix = $dir_prefix . $site_dir;
				//echo "<script language='javascript'>alert($dir_prefix);</script>";
				$post=str_replace("[BB1]","<img src='$dir_prefix/sys/smarty/templates/$template/images/face/BB1.gif'>",$post);
				$post=str_replace("[BB2]","<img src='$dir_prefix/sys/smarty/templates/$template/images/face/BB2.gif'>",$post);
				$post=str_replace("[BB3]","<img src='$dir_prefix/sys/smarty/templates/$template/images/face/BB3.gif'>",$post);
				$post=str_replace("[BB4]","<img src='$dir_prefix/sys/smarty/templates/$template/images/face/BB4.gif'>",$post);
				$post=str_replace("[BB5]","<img src='$dir_prefix/sys/smarty/templates/$template/images/face/BB5.gif'>",$post);
				$post=str_replace("[BB6]","<img src='$dir_prefix/sys/smarty/templates/$template/images/face/BB6.gif'>",$post);
				$post=str_replace("[BB7]","<img src='$dir_prefix/sys/smarty/templates/$template/images/face/BB7.gif'>",$post);
				$post=str_replace("[BB8]","<img src='$dir_prefix/sys/smarty/templates/$template/images/face/BB8.gif'>",$post);
				$post=str_replace("[BB9]","<img src='$dir_prefix/sys/smarty/templates/$template/images/face/BB9.gif'>",$post);
				$post=str_replace("[BB10]","<img src='$dir_prefix/sys/smarty/templates/$template/images/face/BB10.gif'>",$post);
				$post=str_replace("[BB11]","<img src='$dir_prefix/sys/smarty/templates/$template/images/face/BB11.gif'>",$post);
				$post=str_replace("[BB12]","<img src='$dir_prefix/sys/smarty/templates/$template/images/face/BB12.gif'>",$post);
				$post=str_replace("[BB13]","<img src='$dir_prefix/sys/smarty/templates/$template/images/face/BB13.gif'>",$post);
				$post=str_replace("[BB14]","<img src='$dir_prefix/sys/smarty/templates/$template/images/face/BB14.gif'>",$post);
				$post=str_replace("[BB15]","<img src='$dir_prefix/sys/smarty/templates/$template/images/face/BB15.gif'>",$post);
				$post=str_replace("[BB16]","<img src='$dir_prefix/sys/smarty/templates/$template/images/face/BB16.gif'>",$post);
				$post=str_replace("[BB17]","<img src='$dir_prefix/sys/smarty/templates/$template/images/face/BB17.gif'>",$post);
			    $post=str_replace("[BB18]","<img src='$dir_prefix/sys/smarty/templates/$template/images/face/BB18.gif'>",$post);
			    $post=str_replace("[BB19]","<img src='$dir_prefix/sys/smarty/templates/$template/images/face/BB19.gif'>",$post);
			    $post=str_replace("[BB20]","<img src='$dir_prefix/sys/smarty/templates/$template/images/face/BB20.gif'>",$post);
			    $post=str_replace("[BB21]","<img src='$dir_prefix/sys/smarty/templates/$template/images/face/BB21.gif'>",$post);
			    $post=str_replace("[BB22]","<img src='$dir_prefix/sys/smarty/templates/$template/images/face/BB22.gif'>",$post);
			    $post=str_replace("[BB23]","<img src='$dir_prefix/sys/smarty/templates/$template/images/face/BB23.gif'>",$post);
			    $post=str_replace("[BB24]","<img src='$dir_prefix/sys/smarty/templates/$template/images/face/BB24.gif'>",$post);
			    $post=str_replace("[BB25]","<img src='$dir_prefix/sys/smarty/templates/$template/images/face/BB25.gif'>",$post);
			    $post=str_replace("[BB26]","<img src='$dir_prefix/sys/smarty/templates/$template/images/face/BB26.gif'>",$post);
			}
			return $post;
		}
		//[CODE]标签解析器
		function phpcode($code){
			$code_temp = explode("<br />",$code);
			$code = str_replace("<br />","",$code);
			$code = str_replace("&nbsp;", " ", $code);
			$code=str_replace('%a%','',$code);
			$code=str_replace("│","|",$code);
			$count_code=count($code_temp) + 1;
			$code="<br><hr width=90%><center><font color=red>以下是代码:</font><br><TEXTAREA READONLY name=textfield rows=$count_code style=WIDTH:90% class=\"code\">$code</textarea></center><hr width=90%><br>";
		return $code;
	}
		//HTML标签解析器
		function htmlcode($code){
			$code_temp = explode("<br />",$code);
			$code = str_replace("<br />","",$code);
			$code = str_replace("&nbsp;", " ", $code);
			$code = str_replace('%a%','',$code);
			$code = str_replace("│","|",$code);
			$count_code=count($code_temp) + 1;
			$code="<table width=94% cellspacing=0 class='noborder' align=center bgcolor=#F9F9F9><tr>
			<td align='center'>
			<SCRIPT>function runEx(){var winEx = window.open('', '', 'resizable,scrollbars'); winEx.document.open('text/html', 'replace');winEx.document.write(unescape(event.srcElement.parentElement.children[2].value));}</SCRIPT>HTML代码如下:<BR><TEXTAREA style=WIDTH:90% name=textfield rows=$count_code>$code</TEXTAREA><INPUT onclick=runEx() type=button value=运行此HTML代码 class='button'>[Ctrl+A 全部选择 提示：你可先修改部分代码，再按运行]</TD></TR></TABLE>";
			return $code;
		}
		//判断版本号是否符合系统要求
		function check_php_version($needed_version){
			$current_version = phpversion();
			$current_versions_sub = explode('.',$current_version);
			$needed_version_sub = explode('.',$needed_version);
			$count = 0;
			if (count($needed_version_sub) < count($current_versions_sub)) {
				$count = count($needed_version_sub);
			}
			else 
				$count = count($current_versions_sub);
			for ($i = 0; $i < $count;$i++){
				if ($current_versions_sub[$i] < $needed_version_sub[$i]) {
					die('<h1><b><font color="FF0000"><center>
					您当前PHP的版本为:' . $current_version . '<br>
					您PHP的版本低于系统所需的最低版本<br>
					推荐使用版本' . $needed_version . '及其以上
					</center></font></b></h1>');
				}
			}
		}
		//显示重定向窗口
		function show_relocating($fileurl,$web_settings,$message){
			global $sysinfo;
			$sys_dirs_array = explode('/',get_current_dir_of_the_site());
			$site_dir = $sys_dirs_array[1];
			$site_url = 'http://' . $_SERVER['SERVER_ADDR'] . "/$site_dir";
			header("Content-Type: text/html; charset=utf-8");
			echo <<<RELOCATE1
				<html>
					<head>				
					<meta http-equiv='Content-Type' content="text/html; charset=UTF-8">
					<meta name="robots" content="index,follow">
RELOCATE1;
			
					echo "<meta http-equiv='refresh' content='1;url=" .$fileurl ."'>";
					
					echo <<<RELOCATE2
					<title>转向中......</title>
					<style type='text/css'>
					body {font-family: Verdana;FONT-SIZE: 9pt;MARGIN: 0;color: #000000;background: #ffffff;}
					td {FONT-SIZE: 9pt;}
					a { TEXT-DECORATION: none;}
					a:hover{ text-decoration: underline;}
					img {border:0;}
					.index_font{color: #3A4F6C;background-color:#EBEBEB; font-weight:bold;padding: 5px;}
					.index_font a{color: #3A4F6C;font-weight:bold;padding: 5px;}
					</style>
					</head>
					<body vlink='#333333' link='#333333'>
					<br>
					<table width='100%' cellspacing='0' cellpadding='0' height='90%' align='center'>
					<tr align='center' valign='middle'><td>
					<table cellspacing='1' cellpadding='10' bgcolor='#666666' width='600'>
					<tr><td class='index_font' align='center' bgcolor=#9999cc><p>
RELOCATE2;
					echo '<a href="' . $site_url . '">[' . $sysinfo['sitename'] . ']</a> &raquo; 提示您&nbsp;<br><br>';
					echo $message .'<br><br>如果您的浏览器没有自动跳转,请点击<a href="' .  $fileurl . '">这里</a></p>';
					echo '</td></tr></table></td></tr></table></body></html>';
		}
		//注册会话变量
		function regist_user_info($user_infos,$session_started){
			if (!$session_started) {
				$session_ok = session_start();
				if (!$session_ok) {
					show_normal_mesR('无法启动会话<br>请联系管理员','会话启动失败','注册');
				}
			}
			else {
				$_SESSION['user_name'] = $user_infos['user_name'];
				$_SESSION['user_md5_pass'] =sha1(md5( $user_infos['user_pass']));
				$_SESSION['user_email'] = $user_infos['user_email'];
				$_SESSION['user_gander'] = $user_infos['user_gander'];
				$_SESSION['user_age'] = $user_infos['user_age'];
				$_SESSION['self_mes'] = $user_infos['self_mes'];
				$_SESSION['uid'] = $user_infos['uid'];
				$_SESSION['gid'] = $user_infos['gid'];
				$_SESSION['blog_album_describe'] = $user_infos['blog_album_describe'];
				$_SESSION['photo_album_name'] = $user_infos['photo_album_name'];
			}
		}
		//注册COOKIE变量
		function set_cookie($user_name,$user_pass,$life_time){
			$result1 = setcookie('user_name',$user_name,$life_time);
			$result2 = setcookie('user_sha1_pass',sha1(md5($user_pass)),$life_time);
			if ($result1 && $result2) {
				return false;
			}
			else 	
				return true;
		}
		//销毁COOKIE变量
		function destory_cookie(){
			$result1 = setcookie('user_name','',0);
			$result2 = setcookie('user_sha1_pass','',0);
			if ($result1 && $result2) {
				return false;
			}
			else 	
				return true;
		}
		//显示验证码
		function show_validating_code($validating_code){
			Header("Content-type: image/JPEG");		
			$im = imagecreate(62,20); //制定图片背景大小		
			$black = ImageColorAllocate($im, 0,0,0); //设定三种颜色
			$white = ImageColorAllocate($im, 255,255,255); 
			$gray = ImageColorAllocate($im, 120,120,120); 
			imagefill($im,0,0,$gray); //采用区域填充法，设定（0,0）
			//将四位整数验证码绘入图片 
			
			imagestring($im, 5, 10, 3, $validating_code, $white);
			// 用 col 颜色将字符串 s 画到 image 所代表的图像的 x，y 座标处（图像的左上角为 0, 0）。
			//如果 font 是 1，2，3，4 或 5，则使用内置字体
			for($i=0;$i<200;$i++) //加入干扰象素 
			{ 
				$randcolor = ImageColorallocate($im,rand(200,255),rand(200,255),rand(200,255));
				imagesetpixel($im, rand()%70 , rand()%30 , $randcolor); 
			}
			imagejpeg($im);
			ImageDestroy($im);
		}
		//获取当前模板
		function get_current_template(){
			return 'defaults';
		}
		/**
		 * @param 有BKLOG的日期		$log_days
		 * @param 模板名称				$templates
		 * @param 文件夹前缀			$prefix_dir
		 * @param 当前日期   			$year_month_day
		 * 
		 * 自动日历生成JS,将其放入一个页面内,
		 * 自动生成日历
		 * 
		 * @return 整个日历生成的JS代码
		 */
		function get_calendar_js($log_days,$templates,$prefix_dir,$year_month_day,$uid_str = ''){
			$calendar = <<<calendar
			<span id="cc"></span>
						<script language="javascript">
							function showlink(dt,dm)
							{
								dc=dt;dt=dt+",";
								var strpostdd="{$log_days}";
								d = new Date();
								if(strpostdd.indexOf(dt)!=-1)
								{	
									if(dm!=d.getDate())
									return "<div class=hasrecord><a href=index.php?day="+dc+"{$uid_str}><font class=eachdaytext>"+dm+"</font></a></div>";	
									else		
									{			
										if (dm>d.getDate())		
										{				
											return "<span class=cc>"+dm+"</span>";
										}
										else			
										{			
											return "<div class=today><a href=index.php?day="+dc+" ><font class=eachdaytext>"+dm+"</font></a></div>";			
										}		
									}	
								}	
								else	
								{	
									if(dm==d.getDate())		
										return "<div class=today>"+dm+"</span>";	
									else		
										return "<span class=cc>"+dm+"</span>";	
								}
							}
							
							function showcc(yy,mm,dd){
								mm--;
								var arrdd=new Array(31,28,31,30,31,30,31,31,30,31,30,31);
								if(dd==1)
									dd=arrdd[mm];
								switch(mm)
								{
									case 0:strmm="一月"		
										break;
									case 1:strmm="二月"		
										break;
									case 2:strmm="三月"		
										break;
									case 3:strmm="四月"	
										break;
									case 4:strmm="五月"	
										break;
									case 5:strmm="六月"	
										break;
									case 6:strmm="七月"	
										break;
									case 7:strmm="八月"	
										break;
									case 8:strmm="九月"	
										break;
									case 9:strmm="十月"	
										break;
									case 10:strmm="十一月"	
										break;
									case 11:strmm="十二月"	
										break;
								}
								var thisyear=yy;
								var thismonth=mm;
								var lastday=dd;
								if(thismonth==1){
									if (thisyear%4==0 || (thisyear%100==0 && thisyear%400==0))	
									{	
										lastday=29;	
										arrdd[1]=29;	
									}
									else	
									{
										lastday=28;
										arrdd[1]=28;	
									}
								}
								tempyy=yy-1;
								if(mm!=1)	
									tempmm=mm;
								else	
									tempmm=1;
								if(tempmm<1)	
								{
									tempmm=1;	
									tempdd=arrdd[0];
								}
								else
								{
									tempdd=arrdd[mm-1];
								}
								if(mm!=12)	
									tempmm1=mm+2;
								else	
									tempmm1=12;
								if(tempmm1>12)	
								{
									tempmm1=12;	
									tempdd1=arrdd[11];
								}
								else	
								{
									tempdd1=arrdd[mm+1];
								}
								tempyy1=yy+1;
								tempstr="<table width=100% border=0 cellspacing=1 cellpadding=2 class=mainddbg id=cctb><tr><td colspan=7 class=headbg><table width=100% cellspacing=0 cellpadding=0 class=mainddbg>";
								tempstr+="<tr><td align=left width=32 background=\"{$prefix_dir}sys/smarty/templates/{$templates}/images/cbg.gif\" class=mainddbg><span class=hd  title='上一年' onclick=showcc("+tempyy+","+parseInt(mm+1)+","+dd+")>&lt;&lt;</span> <span class=hd title='上一月' onclick=showcc("+yy+","+tempmm+","+tempdd+")>&lt;</span></td>";
								tempstr+="<td align=center class=cc background=\"{$prefix_dir}sys/smarty/templates/{$templates}/images/cbg.gif\" class=mainddbg><font class=datehead><b>:"+strmm+" "+yy+":</b></font></td>";
								tempstr+="<td align=right width=32 background=\"{$prefix_dir}sys/smarty/templates/{$templates}/images/cbg.gif\" class=mainddbg><span class=hd title='下一月' onclick=showcc("+yy+","+tempmm1+","+tempdd1+")>&gt;</span><span class=hd title='下一年' onclick=showcc("+tempyy1+","+parseInt(mm+1)+","+dd+")>&gt;&gt;</span></td></tr></table></td></tr>";
								tempstr+="<tr class=cc><td align=center class=weekday>日</td><td align=center class=weekday>一</td><td align=center class=weekday>二</td><td align=center class=weekday>三</td><td align=center class=weekday>四</td><td align=center class=weekday>五</td><td align=center class=weekday>六</td></tr>";
								tempstr+="<tr>";
								thisdd = new Date();
								thisdd.setFullYear(thisyear,thismonth,1);
								firstday=thisdd.getDay();
								cmi=42;
								if (lastday<31 || firstday==0)
									cmi=36;
								for(i=0;i<cmi;i++)
								{
									tempstr+="<td class=eachdaybg><div align=center>";	
									if (firstday<=i && i<firstday+lastday)		
									{
										cs=i-firstday+1;		
										cd=(yy+"-"+parseInt(mm+1)+"-"+cs).toString();		
										tempstr+=showlink(cd,cs);
									}
									tempstr+="</center></td>";	
									if ((i+1) % 7 ==0)		
										tempstr+="</tr><tr id=tb>";
									}
									tempstr+="</tr></table>";
									cc.innerHTML=tempstr;
									newtb=document.all("tb");
									for(j=0;j<newtb.length;j++)
									{
										if (newtb[j].innerHTML=="")
										{	
											newtb[j].removeNode(true);	
										}
									}
									if(cctb.rows[cctb.rows.length-1].cells[0].innerText=="")	
									cctb.deleteRow();
								}
							showcc({$year_month_day});
						</script>
calendar;
			return $calendar;
		}
		/**
		 * 获取客户端浏览器
		 *
		 * @return 用户浏览器类型
		 */
		function get_client_browser(){
			$browser = '未知';
			if (($browser_ver = stristr($_SERVER["HTTP_USER_AGENT"], "opera"))) {
				$browser = substr($browser_ver,0,strlen('opera') + 5);
			}
			elseif (($browser_ver = stristr($_SERVER["HTTP_USER_AGENT"], "msie"))){
				$browser = 'IEXPLORE ' . substr($browser_ver,strlen('msie'),4);
			}
			else if (($browser_ver = stristr($_SERVER["HTTP_USER_AGENT"], "firefox"))) {
				$browser = substr($browser_ver,0,strlen('firefox') + 8);
			}
			else if (($browser_ver = stristr($_SERVER["HTTP_USER_AGENT"], "netscape"))) {
				$browser = substr($browser_ver,0,strlen('Netscape') + 7);
			}
			else if (($browser_ver = stristr($_SERVER["HTTP_USER_AGENT"], "mozilla"))) {
				$browser = substr($browser_ver,0,strlen('mozilla') + 4);
			}
			return $browser;
		}
		/**
		 * 获取客户端系统类型
		 * @return unknown
		 */
		function get_client_system(){
			$system_type = '未知';
			if (($system_ver = stristr($_SERVER["HTTP_USER_AGENT"], "NT 5.2"))) {
				$system_type = 'WINDOWS 2003';
			}
			elseif (($system_ver = stristr($_SERVER["HTTP_USER_AGENT"], "NT 5.1"))){
				$system_type = 'WINDWOS XP';
			}
			elseif (($system_ver = stristr($_SERVER["HTTP_USER_AGENT"], "NT 5.0"))){
				$system_type = 'WINDWOS XP';
			}
			elseif (($system_ver = stristr($_SERVER["HTTP_USER_AGENT"], "NT 4"))){
				$system_type = 'WINDWOS 2000';
			}
			elseif (($system_ver = stristr($_SERVER["HTTP_USER_AGENT"], "98"))){
				$system_type = 'WINDWOS 98';
			}
			elseif (($system_ver = stristr($_SERVER["HTTP_USER_AGENT"], "Me"))){
				$system_type = 'WINDWOS Me';
			}
			elseif (($system_ver = stristr($_SERVER["HTTP_USER_AGENT"], "95"))){
				$system_type = 'WINDWOS 95';
			}
			elseif (($system_ver = stristr($_SERVER["HTTP_USER_AGENT"], "linux"))){
				$system_type = 'LINUX';
			}
			elseif (($system_ver = stristr($_SERVER["HTTP_USER_AGENT"], "freebsd"))){
				$system_type = 'FREEBSD';
			}
			elseif (($system_ver = stristr($_SERVER["HTTP_USER_AGENT"], "unix"))){
				$system_type = 'UNIX';
			}
			return $system_type;
		}
		/**
		 * 将从数据库中获得的字符串解码为可以供浏览器显示的
		 * 经过编码后的字符串
		 *
		 * @param string $str 				需要解码的字符串
		 * @param BOOL $with_ubb_change		是否需要进行UBB编码
		 * 
		 * @return string					返回经过解码以及编码的字符串
		 */
		function get_html_code($str,$dir_prefix = './',$template = 'default',$with_ubb_change = false,$only_ubb = false){
			$str = STRIP_stripslashes($str);
			$str = htmlspecialchars($str);
			if ($with_ubb_change) {
				if (!$only_ubb) {
					$allow = array('pic'=>1,'flash'=>1,'fontsize'=>1,'wdbimg'=>1,'wdbcodes'=>1,'mpeg'=>1,'iframe'=>1);
				}
				else {
					$allow = array('pic'=>1,'flash'=>0,'fontsize'=>1,'wdbimg'=>1,'wdbcodes'=>1,'mpeg'=>0,'iframe'=>0);
				}
				
				$str = ubb_create($str,$allow);
				$str = site_face_tage($str,$template,get_current_dir_of_the_site(),$dir_prefix);
			}
			return $str;
		}
		//获取当前网站所在文件夹
		function get_current_dir_of_the_site($only_site_dir = false,$depth_of_this_file = 1){
			if (!$only_site_dir) {
				return dirname($_SERVER['PHP_SELF']);
			}
			else 
			{
				$sys_dirs_array = explode('/',dirname($_SERVER['PHP_SELF']));
				$count = count($sys_dirs_array);
				$aaa = '.';
				for ($i = 1; $i < $count - $depth_of_this_file; $i++){
					$aaa .= '/' . $sys_dirs_array[$i];
				}
				$aaa .= '/';
				return $aaa;
			}
		}
		/**
		 * 获取RSS连接字符串
		 *
		 * @param array $web_settings	网站设定
		 * @param tring $template_name	模板名称
		 * @param string $prefix_dir	文件夹前缀
		 * @return string	RSS连接字符串
		 */
		function get_rss_link_str($web_settings,$template_name,$prefix_dir,$only_link = false){
			//获取当前网站绝对路径
			$site_dir = get_current_dir_of_the_site();
			$server_url = get_server();
			$site_url = 'http://' . $server_url . "$site_dir";
			//用户名合法性比较
			$cmp_value = 'user_name=[a-zA-Z0-9_]{4,30}';
			if (!ereg($cmp_value,$_SERVER['QUERY_STRING'],$regs)) {
				$rss_url = $site_url . '/rss.php';
			}
			else {
				$user_name = $regs[0];
				//获取当前用户的RSS
				$rss_url = $site_url . '/rss.php?' . $regs[0];
			}
			$rss_str = '';
			if (!$only_link) {
				$rss_str = $rss_url;
			}
			else {
				$rss_str = "<center><a href='$rss_url' target='_blank'><img src='{$prefix_dir}sys/smarty/templates/{$template_name}/images/blog/rss.gif' alt='订阅最新文章'></a></center>";
			}
			return $rss_str;
		}
		/**
		 * 获取主机URL
		 *
		 * @return string 主机URL或者主机IP
		 */
		function get_server(){
			if ($_SERVER['HTTP_HOST'] == '') {
				return $_SERVER['SERVER_ADDR'];
			}
			else 
				return $_SERVER['HTTP_HOST'];
		}
		/**
		 * 打印某关联数组里面成员的值
		 * 测试用
		 *
		 * @param array $a
		 */
		function e_fore($a){
			foreach ($a as $key => $value) {
				if (is_array($value)) {
					e_fore($value);
				}
				else 
					echo "$key => $value<br>";
			}
			echo '<br>----------------------------------------------<br>';
		}
		/**
		 *
		 * @param 经过检测合格的用户名 $checked_user_name
		 * 
		 * @param 数据库设定关联数组   $db_setting
		 * 
		 * @param 模板类对象        	$smarty
		 * 
		 * @param 网站全局设定关联数组 $web_settings
		 * 
		 * 获取上次登陆的时间
		 * 通过用户名在数据库
		 * 中查找该用户上次合
		 * 法登陆的时间
		 * 
		 * @return  返回上次用户登陆的完整时间
		 */
		function last_login($checked_user_name,$db_setting,$smarty,$web_settings){
			$dbhost    = $db_setting['host'];
			$dbuser    = $db_setting['user'];
			$dbpw      = $db_setting['pass'];
			$dbname    = $db_setting['dbname'];
			$prefix_tb = $db_setting['tb_pre'];
			
			$loginlogid = time();
			$ipaddres = get_remote_ip();
			$date = get_date(time());
			//写用户信息表
			@$db = new mysqli($dbhost,$dbuser,$dbpw,$dbname);
			if (mysqli_connect_errno($db)) {
				show_error_mes($db_setting['dir'],$smarty,'无法连接数据库<br>如果该错误多次出现<br>请通知管理员',$web_settings);
			}
			$sql = "SELECT `loginlogid`,`date` FROM `" . $prefix_tb . "loginlog` WHERE (`result`=1 AND `username`='$checked_user_name') ORDER BY `loginlogid` DESC LIMIT 0 , 2 ";
			$result = $db->query($sql);
			if ($result === false) {
				show_error_mes($db_setting['dir'],$smarty,'无法连接数据库,<br>有可能是数据库出错',$web_settings);
			}
			$num_rows = $result->num_rows;
			//用户未登陆(或者注册后第一次登陆,返回用户注册时间)
			if ($num_rows < 1) {
				$last_login = get_date_time(time());
				@$db = new mysqli($dbhost,$dbuser,$dbpw,$dbname);
				if (mysqli_connect_errno($db)) {
					show_error_mes($db_setting['dir'],$smarty,'无法连接数据库<br>如果该错误多次出现<br>请通知管理员',$web_settings);
				}
				$sql = "SELECT `uid` FROM `" . $prefix_tb . "member_info` WHERE (`user_name`='$checked_user_name') ORDER BY `uid` DESC";
				$result = $db->query($sql);
				if ($result === false) {
					show_error_mes($db_setting['dir'],$smarty,'无法连接数据库,<br>有可能是数据库出错',$web_settings);
				}
				$num_rows = $result->num_rows;
				if ($num_rows < 1) {
					show_error_mes($db_setting['dir'],$smarty,'您恐怕还没注册吧<br>或者您还没登陆',$web_settings);
				}
				$date = $result->fetch_object();
				$last_login = get_date_time($date->uid);
			}
			else {
				$date = $result->fetch_object();
				//如果用户刚才注册,返回用户第一次登陆的时间
				if ($num_rows == 1) {
					$last_login =get_date_time($date->loginlogid);
					return $last_login;
				}
				$date = $result->fetch_object();
				$last_login =get_date_time($date->loginlogid);
			}
			$result->close();
			$db->close();
			return $last_login;
		}
		/**
		 * 获取特定作者文章数目
		 *
		 * @param long $uid							当前用户组ID
		 * @param array $db_setting					数据库设定	
		 * @param array $web_settings				网站设定
		 * @param object $smarty					模板对象
		 * @param long $author_id					文章作者ID
		 * @return long								文章数目
		 */
		function get_total_blogs($gid,$db_setting,$web_settings,$smarty,$author_id = false){
			$dbhost    = $db_setting['host'];
			$dbuser    = $db_setting['user'];
			$dbpw      = $db_setting['pass'];
			$dbname    = $db_setting['dbname'];
			$prefix_tb = $db_setting['tb_pre'];
			$prefix_dir = get_dir_prefix($db_setting['dir']);
			$uid = $_SESSION['uid'];
			
			@$db = new mysqli($dbhost,$dbuser,$dbpw,$dbname);
			if (mysqli_connect_errno($db)) {
				show_error_mes($db_setting['dir'],$smarty,'无法连接数据库<br>如果该错误多次出现<br>请通知管理员',$web_settings);
			}
			//当文章隐藏的时候只有管理员和发表文章的用户本人能够查看该文章(获取文章总数的时候需要区别对待)
			//给定作者
			if (is_numeric($author_id) && $author_id != '') {
				if ($gid != 99 ) {
					$sql = "SELECT COUNT(*) AS count FROM " . $prefix_tb ."blog WHERE((hidden=0 OR (hidden=1 AND authorid=$uid)) AND authorid=$author_id)";
				}
				//管理员则显示全部文章
				else
					$sql = "SELECT COUNT(*) AS count FROM " . $prefix_tb ."blog WHERE(authorid=$author_id)";
			}
			//未给定作者
			else {
				if ($gid != 99 ) {
					$sql = "SELECT COUNT(*) AS count FROM " . $prefix_tb ."blog WHERE(hidden=0 OR (hidden=1 AND authorid=$uid))";
				}
				//管理员则显示全部文章
				else
					$sql = "SELECT COUNT(*) AS count FROM " . $prefix_tb ."blog";
			}
			
			@$total_page = get_one($db_setting,$sql);
			if ($total_page === false) {
				show_error_mes($db_setting['dir'],$smarty,'无法连接数据库,<br>有可能是数据库出错',$web_settings);
			}
			$total_blogs = $total_page['count'];
			$db->close();
			return $total_blogs;
		}
		/**
		 * 获取某个特定页面的HTML代码
		 *
		 * @param unknown_type $db_setting
		 * @param unknown_type $web_settings
		 * @param unknown_type $smarty
		 * @param unknown_type $num_per_page
		 * @param unknown_type $current_page
		 * @param unknown_type $total_blogs
		 * @param unknown_type $template
		 * @param unknown_type $uid
		 * @return unknown
		 */
		function get_current_page_str($db_setting,$web_settings,$smarty,$num_per_page,$current_page,$total_blogs,$template = 'defaults',$uid = false){
			$dbhost    = $db_setting['host'];
			$dbuser    = $db_setting['user'];
			$dbpw      = $db_setting['pass'];
			$dbname    = $db_setting['dbname'];
			$prefix_tb = $db_setting['tb_pre'];
			$prefix_dir = get_dir_prefix($db_setting['dir']);
			@$db = new mysqli($dbhost,$dbuser,$dbpw,$dbname);
			if (mysqli_connect_errno($db)) {
				show_error_mes($db_setting['dir'],$smarty,'无法连接数据库<br>如果该错误多次出现<br>请通知管理员',$web_settings);
			}
			//总共的页数
			$total_pages = (integer)($total_blogs / $num_per_page);
			$start_page = $current_page * $num_per_page;
			//获取分页字符串
			$pages_str = pages($total_pages,$current_page,$num_per_page,$uid);
			//赋值分页
			$smarty->assign('pages',$pages_str);
			//查询分页
			if (is_numeric($uid) && $uid != false) {
				$sql = "SELECT * FROM `" . $prefix_tb . "blog` WHERE(authorid=$uid) ORDER BY `posttime` DESC LIMIT $start_page , $num_per_page  ";
			}
			else 
				$sql = "SELECT * FROM `" . $prefix_tb . "blog` ORDER BY `posttime` DESC LIMIT $start_page , $num_per_page  ";
			$result = $db->query($sql);
			if ($result === false) {
				show_error_mes($db_setting['dir'],$smarty,'无法连接数据库,<br>有可能是数据库出错',$web_settings);
			}
			$num_rows = $result->num_rows;
			//没有文章
			if ($num_rows < 1) {
				return '<tr class ="noborder"><td class="noborder"><center><font color="red">目前没有文章发表</font></center></td></tr>';
			}
			$blog_content = '';
			for ($i = 0; $i < $num_rows; $i++){
				$article_infos = $result->fetch_object();
				$article_infos = init_article_infos($article_infos->blog_id,$article_infos->article,$article_infos->article_title,$article_infos->author,$article_infos->article_info,$article_infos->authorid,$article_infos->sort_id,$article_infos->hits,$article_infos->replies,$article_infos->replies_page,$article_infos->lastpost,$article_infos->lastposter,$article_infos->lastposterid,$article_infos->posttime,$article_infos->hidden,$article_infos->isparseurl,$article_infos->ipaddress);
				$blog_content .= show_article($article_infos,$prefix_dir,$template,$gid,'');
			}
			$db->close();
			return $blog_content;
		}
		/**
		 * 将页码按10页一组分页
		 *
		 * @param int $total_pages
		 * @param int $current_page
		 * @return string
		 */
		function pages($total_pages,$current_page,$num_per_page,$uid=false){
			if (is_numeric($uid) && $uid != false) {
				$uid_str = '&uid=' . $uid;
			}
			else {
				$uid_str = '';
			}
			//如果当前页超过了最大页数,当前页等于最大页
			if ($current_page > $total_pages) {
				$current_page = $total_pages;
			}
			//每页文章数不能少于2
			if ($num_per_page < 2) {
				$num_per_page = 2;
			}
			$pages = "&nbsp;共" . ($total_pages + 1) . "页";
			//当前页在第几个10页
			$current_page_of_ten = (integer)($current_page / 10);
			//总共有多少个10页
			$total_pages_of_ten = (integer)($total_pages / 10);
			//当前页码在该10页的第几页
			$num_of_current_page_of_ten = $current_page % 10;
			//生成分页
			$end_tens = $pre_tens = $temp = '';
			//显示某个具体的10页
			for ($i = 0 ; $i < 10 ; $i++){
				$this_page = $current_page_of_ten * 10 + $i;	//具体每页页码
				if ($this_page == $current_page) {
					$true_current_page = $current_page + 1;
					$temp .= "&nbsp;$true_current_page&nbsp;";
				}
				else {
					$true_this_page = $this_page + 1;
					$temp .= "<a href='index.php?current_page=$this_page" . $uid_str . "'>$true_this_page</a>";	
				}
				//当是最后一页的时候,退出循环
				if ($this_page == $total_pages) {
					break;
				}
			}
			//显示10页翻页
			for ($i = 0 ; $i < $total_pages_of_ten ; $i++){
				//循环到第几个十页
				$this_page_of_ten = $i * 10;
				//循环中的十页小于当前十页
				if ($i < $current_page_of_ten) {
					$pre_tens .= "<a href='index.php?current_page=$this_page_of_ten" . $uid_str . "'>.&nbsp;</a>";
				}
				//循环中的十页等于当前十页
				if ($i == $current_page_of_ten) {
					//如果不是第一个10页,显示向前翻页
					if ($i > 0) {
						$pre_ten_page = ($i - 1) * 10;
						$head = "<a href='index.php?current_page=" . $pre_ten_page . $uid_str . "'>" . htmlspecialchars("<< ") . "</a>";
					}
					if ($i < $total_pages_of_ten + 1) {
						$back_ten_page = ($i + 1) * 10;
						$end = "<a href='index.php?current_page=$back_ten_page'" . $uid_str . ">" . htmlspecialchars(" >>") . "</a>";
					}
				}
				//当为最后一页时
				if ($head == '' && $i == $current_page_of_ten - 1) {
						$pre_ten_page = $i * 10;
						$head = "<a href='index.php?current_page=" . $pre_ten_page . $uid_str . "'>" . htmlspecialchars("<< ") . "</a>";
				}
				//循环中的十页大于当前十页
				if ($i > $current_page_of_ten - 1) {
					$back_this_page_of_ten = $this_page_of_ten + (1 * 10);
					$back_tens .= "<a href='index.php?current_page=$back_this_page_of_ten" . $uid_str . "'>&nbsp;.</a>";
				}
			}
			$temp = $head . $pre_tens . $temp . $back_tens . $end . $pages;
			return $temp;
		}
		/**
		 * 执行查询
		 *
		 * @param array $db_setting
		 * @param array $web_settings
		 * @param array $smarty
		 * @param str $sqls
		 * @return src
		 */
		function query($db_setting,$web_settings,$smarty,$sqls){
			$dbhost    = $db_setting['host'];
			$dbuser    = $db_setting['user'];
			$dbpw      = $db_setting['pass'];
			$dbname    = $db_setting['dbname'];
			$prefix_tb = $db_setting['tb_pre'];
			
			@$db = new mysqli($dbhost,$dbuser,$dbpw,$dbname);
			if (mysqli_connect_errno($db)) {
				show_error_mes($db_setting['dir'],$smarty,'无法连接数据库<br>如果该错误多次出现<br>请通知管理员',$web_settings);
			}
			$result = '';
			if (is_array($sqls)) {
				$result = array();
				$count = count($sqls);
				for ($i = 0; $i < $count; $i++){
					$result[$i] = $db->query($sqls[$i]);
					if ($result[$i] == false) {
						show_error_mes($db_setting['dir'],$smarty,'无法执行第' . ($i+1) . '句查询语句:<br>' . $sqls[$i] . '<br>数据库错误信息为:<br>' . mysqli_error($db),$web_settings);
					}
				}
			}
			else{
				$result = $db->query($sqls);
				if ($result == false) {
					show_error_mes($db_setting['dir'],$smarty,'无法执行查询语句:<br>' . $sqls . '<br>数据库错误信息为:<br>' . mysqli_error($db),$web_settings);
				}
			}
			return $result;
			$db->close();
		}
		/**
		 * 检测某用户组权限
		 *
		 * @param long $gid
		 * @param array $rights_table
		 * @param string $action
		 * @return bool
		 */
		function check_user_rights($gid,$user_rights_table = false,$rights_table = false,$action = false,$user_name = false){
			if (!$rights_table && (!$action) && $gid == 99) {
				return true;
			}
			else if (!$rights_table && (!$action) && $gid != 99) {
				return false;
			}
			else if (is_numeric($gid) && $user_name != '' && is_array($rights_table) && $action != '' && is_array($user_rights_table)) {
				
				$allow = false;
				if (count($rights_table) < 1) {
					return false;
				}
				else {
					$count = count($rights_table);
					foreach ($rights_table as $key => $value) {
						if ($key == $action) {
							if (is_array($value)) {
								$sub_count = count($value);
								foreach ($value as $sub_value) {
									if ($sub_value == $gid) {
										$allow = true;
									}
								}
							}
							else {
								if ($value == $gid) {
									$allow = true;
								}
							}
						}
					}
					if ($allow == true) {
						if (count($user_rights_table) < 1) {
							return false;
						}
						else {
							$count = count($$rights_table);
							foreach ($user_rights_table as $key => $value) {
								if ($key == $action) {
									if (is_array($value)) {
										$sub_count = count($value);
										foreach ($value as $sub_value) {
											if ($sub_value == $user_name) {
												$allow2 = true;
											}
										}
									}
									else {
										if ($value == $user_name) {
											$allow2 = true;
										}
									}
								}
							}
							
							if ($allow !== true || $allow2 !== true) {
								return false;
							}
						}
					}
				}
				return $allow;
			}
			else {
				return false;
			}
		}
		/**
		 * 检查字符串长度
		 *
		 * @param tring $str
		 * @param long $max_len
		 * @param long $min_len
		 * @return bool
		 */
		function check_len($str,$max_len,$min_len){
			if (strlen($str) > $max_len || strlen($str) < $min_len) {
				return false;
			}
			else {
				return true;
			}
		}
		/**
		 * 保存当前页面的URL
		 *
		 * @return URL
		 */
		function save_base_this_url(){
			$url = basename($_SERVER['PHP_SELF']);
			if ($_SERVER['QUERY_STRING'] != '') {
					$url .= '?' . $_SERVER['QUERY_STRING'];
			}
			$_SESSION['pre_url'] = $url;
			return  $url;
		}
		/**
		 * 获取模板列表
		 */
		function get_tmplte($dir_prefix){
			$dir = opendir($dir_prefix . 'sys/smarty/templates');
			$tmplte_str = '';
			while ($file = readdir($dir)) {
				if (!is_file($file) && $file != '.' && $file != '..') {
					$tmplte_str .= $file . '|';
				}
			}
			return $tmplte_str;
		}
		//写文件
		function writeover($filename,$data,$method="rb+",$iflock=1){
			touch($filename);
			$handle=fopen($filename,$method);
			if($iflock){
				flock($handle,LOCK_EX);
			}
			fputs($handle,"<?php",strlen("<?php"));
			$show = fputs($handle,$data);
			if($method=="rb+") ftruncate($handle,strlen($data));
			fclose($handle);
			return $show;
		}
		/**
		 * 设置脚本运行时间
		 *
		 * @param int $time
		 */
		function set_script_running_time($time){
			if (is_integer($time) && $time > 0 && $time < 60000) {
				set_time_limit($time);
			}
		}

 		function  init_smart_template_obj($template_filename,$temp_dir,$cache_dir,$template_dir){
 			$page = new SmartTemplate( $template_filename );
			$page->temp_dir = $temp_dir;
			$page->cache_dir = $cache_dir;
			$page->template_dir = $template_dir;
			return $page;
 		}

		//删除文件夹
		function deldir($path){
		if (file_exists($path)){
			if(is_file($path)){
				unlink($path);
			} else{
				$handle = opendir($path);
				while ($file = readdir($handle)) {
					if (($file!=".") && ($file!="..") && ($file!="")){
						if (is_dir("$path/$file")){
							deldir("$path/$file");
						} else{
							unlink("$path/$file");
						}
					}
				}
				closedir($handle);
				rmdir($path);
			}
		}
	}
	
	/**
	 * 检查用户是否登陆
	 * 检查未登陆返回-1
	 * 登陆返回 0
	 * @return  true,false
	 */
	function check_user_logedin(){
		if (!isset($_SESSION['user_name']) || $_SESSION['user_name'] == '') {
			$_SESSION['user_name'] = 'guest';
		}
		if ($_SESSION['user_name'] == 'guest') {
			return false;
		}
		else 
			return true;
	}
	
	
?>